import 'package:flutter_clx_base/flutter_clx_base.dart';

typedef Callback = void Function(String? time);

/// 展示日期选择器
showDateTimePicker({
  DateTime? initialDateTime,
  String? dateFormat,
  Callback? onCallback,
}) {
  DatePicker.showDatePicker(
    Get.context!,
    minDateTime: DateTime.parse("2010-01-01"),
    maxDateTime: DateTime.parse("2050-01-01"),
    initialDateTime: initialDateTime,
    locale: DateTimePickerLocale.zh_cn,
    dateFormat: dateFormat,
    pickerMode: DateTimePickerMode.date,
    onMonthChangeStartWithFirstDate: true,
    // show TimePicker
    pickerTheme: DateTimePickerTheme(
        cancelTextStyle: const TextStyle(color: Color(0xFF999999)),
        confirmTextStyle: TextStyle(color: Theme.of(Get.context!).primaryColor),
        showTitle: true,
        titleHeight: 50.0),
    onConfirm: (dateTime, List<int> index) {
      logger.d("选择dateTime dateTime-> $dateTime index-> $index");
      String? time = DateUtil.formatDate(dateTime, format: dateFormat);
      onCallback?.call(time);
    },
  );
}
